package com.ifp.opengate.boot.utils;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * todo
 * </P>
 *
 * @author zhuzh@belink.com
 * @version 0.0.1
 * @className SeqUtil
 * @sine 2020/5/19 14:39
 */
@Component
public final class SeqUtil {

    @Autowired
    RedisUtils redisUtils;
    private String IDC = "G01";

    /**
     * @param incr
     * @return
     */
    private String getSeqUtil(String incr) {
        while (incr.length() < 18) {
            incr = "0" + incr;
        }
        return incr;
    }

    /**
     * 获取TraceId
     * 
     * @param ip 服务器IP
     * @return
     */
    public String getTraceId(String ip) {
        String ips[] = ip.split("\\.");
        String ip16 = "";
        for (int i = 0; i < ips.length; i++) {
            ip16 += Integer.toHexString(Integer.parseInt(ips[i]));;
        }
        long seq = redisUtils.incrseq("sofa_seq_key", 1000, 9000, 1);
        return ip16 + new Date().getTime() + seq;
    }
}
